<template>
	<view class="compose_index">
		<u-navbar :is-back="false" title="">
			<view class="slot_content">
				<view class="nav_img" @click="backTo">
					<image src="@/static/17.svg"></image>
				</view>
				<view class="nav_title">合成</view>
			</view>
		</u-navbar>
		<view class="content">
			<u-swiper :list="swiperList" height="380" border-radius="20"></u-swiper>
			<view class="list">
				<view class="item" v-for="item in list" @click="router(item)">
					<image :src="item.cover" class="item_img"></image>
					<view class="item_view">
						<view class="title">
							<view class="name">{{item.name}}</view>
							<view class="btn not" v-if="item.status==0">未开始</view>
							<view class="btn start" v-else-if="item.status==1">进行中</view>
							<view class="btn end" v-else>已结束</view>
						</view>
						<view class="time">
							<text>{{item.start_date}}</text>
							<image src="@/static/50.svg"></image>
							<text>{{item.end_date}}</text>
						</view>
					</view>
				</view>
			</view>
			<!-- <u-loadmore :status="status" :loadText="$store.state.loadText" @loadmore="loadmore" /> -->
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				swiperList: [],
				list: [],
				page: 1,
				last_page: 1,
				limit: 10,
				status: "loadmore"
			}
		},
		async onLoad() {
			let {
				position,
				list
			} = await this.$u.api.compose();
			position.forEach(item => {
				item.image = item.img;
			});
			this.swiperList = position;
			this.list = list.list;
		},
		async onShow() {},
		onReachBottom: function() {
			this.loadmore();
		},
		methods: {
			async getList() {
				let {
					list
				} = await this.$u.api.compose({
					page: this.page,
					limit: this.limit
				});
				this.last_page = list.last_page;
				list = list.list;
				this.list = this.page == 1 ? list : [...this.list, ...list];
				if (this.last_page == this.page) {
					this.status = 'nomore';
				}
			},
			loadmore() {
				let page = this.page;
				let last_page = this.last_page;
				if (page < last_page) {
					this.page++;
					this.getList();
				}
			},
			backTo() {
				uni.navigateBack()
			},
			router(item) {
				let status = item.status;
				if (status != 1) return;
				let url = `/pages/compose/core?id=${item.id}`;
				uni.navigateTo({
					url
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.compose_index {
		.content {
			padding: 44rpx 30rpx;
			box-sizing: border-box;

			.list {
				padding: 44rpx 0;

				.item {
					width: 100%;
					height: 140rpx;
					margin: 30rpx 0;
					display: flex;

					.item_img {
						width: 140rpx;
						height: 140rpx;
						border-radius: 20rpx;
						margin-right: 30rpx;
					}

					.item_view {
						flex: 1;
						width: 0;
						display: flex;
						flex-direction: column;
						justify-content: space-between;

						.title {
							height: 64rpx;
							display: flex;
							justify-content: space-between;
							align-items: center;

							.name {
								flex: 1;
								width: 0;
								white-space: nowrap;
								text-overflow: ellipsis;
								overflow: hidden;
							}

							.btn {
								width: 150rpx;
								height: 64rpx;
								font-size: 24rpx;
								font-weight: bold;
								border-radius: 10rpx;
								display: flex;
								justify-content: center;
								align-items: center;

								&.start {
									color: #FFFFFF;
									background: #6BD288;
								}

								&.not {
									color: #F8DF64;
									border: 1px solid #F8DF64;
									background: #FEFCF0;
								}

								&.end {
									color: #C2C2C2;
									border: 1px solid #F0F0F0;
								}
							}
						}

						.time {
							height: 48rpx;
							display: flex;
							justify-content: space-between;
							align-items: center;

							text {
								color: #787878;
								font-size: 24rpx;
								font-weight: 400;
								white-space: nowrap;
							}

							image {
								width: 48rpx;
								height: 48rpx;
							}
						}
					}
				}
			}
		}
	}
</style>
